package com.song.book.service.impl;

import com.song.book.dao.BookDao;
import com.song.book.pojo.Book;
import com.song.book.service.BookService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2024/1/5
 * @Version 1.0
 **/
@Service
@Transactional
@Slf4j
public class BookServiceImpl implements BookService {
    @Resource
    private BookDao bookDao;
    @Override
    public List<Book> findBooks() {
        return this.bookDao.findAll();
    }

    @Override
    public Book findBookById(Long id) {
        return this.bookDao.findById(id).get();
    }

    @Override
    public Boolean saveBook(Book book) {
        try{
           this.bookDao.save(book);
           return  true;
        }catch (Exception e){
          log.debug("保存失败");
        }
        return false;

    }

    @Override
    public Boolean deleteBook(Long id) {
        try{
            this.bookDao.deleteById(id);
            return  true;
        }catch (Exception e){
            log.debug("保存失败");
        }
        return false;
    }
}
